# -*- coding: utf-8 -*-
import logging

from celery import shared_task
from django.contrib.auth import get_user_model
from django.test import RequestFactory, Client

logger = logging.getLogger(__name__)


@shared_task()
def async_task(query_params, data, user_id, path, *args, **kwargs):
    result = f'query_params:{query_params},data:{data}'
    logger.info(result)
    user = get_user_model().objects.get(pk=user_id)

    # factory = RequestFactory()
    # request = factory.post(path='post_sync')
    # handle = SyncView.as_view({'post': 'post_sync'})
    # response = handle(request)
    # logger.info(response.data)

    client = Client()
    client.force_login(user)
    response = client.post(
        path,
        data,
    )

    return response.content
